﻿//查询条件公用

var ie6 = ! -[1, ] && !window.XMLHttpRequest;
var ie7= browser.msie && (parseInt(browser.version)) <= 7
var morelistheight = 0;
var Log = { '24': { up: '1', down: '2' }, '25': { up: '3', down: '4' }, '32': { up: '2', down: '3'} }
$(function () {
    //英文版样式 begin
    if (lang == "en") {
        $("#dt_area,#dt_funtype,#dt_expectsalary,#dt_cursalary,#dt_workyear,#dt_enlevel").addClass("dt-twoline");
        $("#divdrop_expectsalaryfrom,#divdrop_expectsalaryto,#divdrop_cursalaryfrom,#divdrop_cursalaryto,#divdrop_degreefrom,#divdrop_degreeto,#divdrop_workyearfrom,#divdrop_workyearto").css("width", "69px");
    }
    //英文版样式 end
    //IE6 特殊处理
    if (ie6) {
        $(".Search_num-set").css("margin-right", "40");
        if (lang == "en") {
            $("#div_keywordtype").css("width", "80px");
        }
        else {
            $("#div_keywordtype").css("width", "50px");
        }
        $("#divdrop_expectsalaryfrom,#divdrop_expectsalaryto,#divdrop_cursalaryfrom,#divdrop_cursalaryto").css("height", "280px");
    }
    if (ie7) {
        $(".controlSet").css("width", "80px");
    }
    var distinction = ($("#" + prefixControlID + "hidmorelistheight").val() != undefined)
    if (!ie7) {
        if (distinction) {
            if ($(".more-list").height() > 0) {
                $("#" + prefixControlID + "hidmorelistheight").val($(".more-list").height())
            }
            morelistheight = $("#" + prefixControlID + "hidmorelistheight").val();
        }
        else {
            morelistheight = $(".more-list").height();
        }
        $(".more-list").css({ "height": "0", "overflow": "hidden" });
    }
    //搜索条件是否要展开
    if ($("#hidShowMore").val() == "1" || $("#" + prefixControlID + "hidShowMore").val() == "1") {
        if (!ie7) {
            $(".more-list").css("height", morelistheight);
            $(".more-list").css("overflow", "inherit");
            if (!distinction) $(".more-list").show();
        }
        else {
            if (!distinction) $(".more-list").show();
        }
        if (!distinction) {
            $(".controlSet i").removeClass("icon-angle-up").addClass("icon-angle-down");
            $(".controlSet").toggleClass("up");
        }
        
    }
    $(".controlSet").click(function () {
        if ($("#hidShowMore").val() == "0" || $("#" + prefixControlID + "hidShowMore").val() == "0") {
            $("#hidShowMore").val("1");
            $("#" + prefixControlID + "hidShowMore").val("1");
            if (!ie7) {
                $(".more-list").css({ "overflow": "hidden" });
                setTimeout(function () { SetMoreListShow(0, 1) }, 50);
                $(".more-list").show();
            }
            else {
                $(".more-list").show();
            }
            $(".controlSet i").removeClass("icon-angle-up").addClass("icon-angle-down");
            var pageNo = $('#pageNo').val();
            if (pageNo) {
                var tmp = pageNo;
                if (pageNo == '28' || pageNo == '29' || pageNo == '30' || pageNo == '31')
                    tmp = '24';
                EHR.Common_AsyncAddLog(pageNo, Log[tmp].down, '');
            }
            else {
                EHR.Common_AsyncAddLog('4', '16', '');
            }
        }
        else {
            $("#hidShowMore").val("0");
            $("#" + prefixControlID + "hidShowMore").val("0");
            if (!ie7) {
                $(".more-list").css({ "overflow": "hidden" });
                setTimeout(function () { SetMoreListShow(morelistheight, 0) }, 50);
            }
            else {
                $(".more-list").hide();
            }
            $(".controlSet i").removeClass("icon-angle-down").addClass("icon-angle-up");
            var pageNo = $('#pageNo').val();
            if (pageNo) {
                var tmp = pageNo;
                if (pageNo == '28' || pageNo == '29' || pageNo == '30' || pageNo == '31')
                    tmp = '24';
                EHR.Common_AsyncAddLog(pageNo, Log[tmp].up, '');
            }
            else {
                EHR.Common_AsyncAddLog('4', '17', '');
            }
        }
        $(".controlSet").toggleClass("up");
    });
    $(".btn-search").attr("href", "javascript:void(0)");
    $("[data-toggle='collapse']").click(function () {
        $(this).parent().parent().siblings().find(".accordion-body").removeClass("in").addClass("collapse");
    });
    $("[id^='" + prefixControlID + "txt_']").click(function () {
        if ($(this).attr("readonly") == true || $(this).attr("readonly") == "readonly") {
            $(this).blur();
            $(this).siblings("a").click();
        }
    });
    //触发下拉框
    $("[id^='icon_']").click(function () {
        $("#div_searchlist .inptext_fl").children("input").css("border-color", "#c4c4c4");
        var controlID = $(this).attr("id").replace("icon_", "");
        if ($("#divdrop_" + controlID).is(":hidden")) {
            $("[id^='divdrop_']").hide();
            $("#divdrop_" + controlID).show();
            var showLength = 0;
            $("#divdrop_" + controlID + " a").each(function () {
                if ($(this).is(":visible")) {
                    showLength += 1;
                    return false;
                }
            });
            if (showLength == 0) {
                $("[id^='divdrop_']").hide();
            }
        }
        else {
            $("[id^='divdrop_']").hide();
        }
    });
    $("[id^='dic_']").live("click", function () {
        if ($(this).attr("id").split('_')[1] == "searchkey") {
            return;
        }
        var controlID = $(this).parent().attr("id").replace("divdrop_", "");
        var controlValue = $(this).attr("id").split('_')[2];
        var controlText = (typeof ($(this)[0].innerText) != "undefined") ? $(this)[0].innerText : $(this)[0].textContent;
        if (controlValue == "99" || (controlValue == "0" && controlID != "sex")) {
            controlValue = "";
        }
        $("#" + prefixControlID + "txt_" + controlID).val(controlText);
        $("#" + prefixControlID + "hid_" + controlID).val(controlValue);
        $(this).parent().hide();
        $("#" + prefixControlID + "txt_" + controlID).css("border-color", "#c4c4c4");
        if (controlID.indexOf("from") != -1) {
            EHRCommonSearch.selectdata(prefixControlID + "txt_" + controlID, prefixControlID + "hid_" + controlID);
        }
        var me = $("#" + prefixControlID + "txt_" + controlID);
        if (me.attr('placeholder') == controlText) {
            me.css('color', '#b4b4b4');
        } else {
            me.css('color', '#3b3b3b');
        }
    });
    $("#div_area a").click(function () {
        resume_areaLayer.initAreaData(prefixControlID + 'txt_area_search', prefixControlID + 'hid_area_search', 0, 0, 0, 'search_area_weizao', 1, { limitNum: 1, mode: 1 });
    });
    $("#div_funtype a").click(function () {
        showFunDivNew(this, prefixControlID + 'hid_funtype_search', prefixControlID + 'txt_funtype_search', false, { limitNum: 3, maxSelectNum: 3, mode: 1 });
    });
    $("#div_industry a").click(function () {
        showIndustryDiv(this, prefixControlID + 'hid_industry_search', prefixControlID + 'txt_industry_search', false, { limitNum: 1, maxSelectNum: 1, mode: 1 });
    });
    $("#div_hukou a").click(function () {
        resume_areaLayer.initAreaData(prefixControlID + 'txt_hukou_search', prefixControlID + 'hid_hukou_search', 0, 1, 0, 'search_area_weizao', 1, { limitNum: 1, mode: 1 });
    });
    $("#div_major a").click(function () {
        showMajorDiv(this, prefixControlID + 'hid_major_search', prefixControlID + 'txt_major_search', false, { limitNum: 3, maxSelectNum: 3, mode: 1 });
    });
    $("#div_label a").click(function () {
        EHRCommonSearchLabel.showLabelData({ maxSelectNum: 5, showid: prefixControlID + "txt_label", hidid: prefixControlID + "hid_label", hidtitleid: prefixControlID + "hid_titlelabel" });
    });

    EHRCommonSearch.CreatePlaceholder();
    EHRCommonSearch.RefreshBorderColor();
    EHRCommonSearch.InitSelectData();
});
var SetMoreListShow = function (height, type) {
    $(".more-list").css("height", height);
    if (height == morelistheight && type == 1) {
        $(".more-list").css("overflow", "inherit");
        return;
    }
    else if (height == 0 && type == 0) {
        $(".more-list").hide();
        return;
    }
    if (type == 1) {
        height += 20;
        if (height > morelistheight) {
            height = morelistheight;
        }
    }
    else {
        height -= 20;
        if (height < 0) {
            height = 0;
        }
    }
    setTimeout(function () { SetMoreListShow(height, type) }, 50);
}
var EHRCommonSearch = {};
EHRCommonSearch.RefreshBorderColor = function () {
    $("#div_searchlist .inptext_fl").each(function () {
        var me = $(this).children("input");
        if (me.length > 0) {
            if ($(me).attr("id") == prefixControlID + "txt_keyword") {
                me.focus(function () {
                    $(me).parent("div").css("border-color", "#5191ce");
                }).blur(function () {
                    $(me).parent("div").css("border-color", "#c4c4c4");
                });
            }
            else if (me.attr("type") == "text" && !me.attr("readonly")) {
                me.focus(function () {
                    me.css("border-color", "#5191ce");
                }).blur(function () {
                    me.css("border-color", "#c4c4c4");
                });
            }
            else if (me.attr("type") == "text") {
                $(this).click(function () {
                    me.css("border-color", "#5191ce");
                });
            }
        }
    });
}
//文本框默认值及字体颜色
EHRCommonSearch.CreatePlaceholder = function () {
    if (navigator.userAgent.indexOf('MSIE') >= 0) {
        $('#div_searchlist input').each(function () {
            var me = $(this);
            var ph = me.attr('placeholder');
            if (ph) {
                if (me.val() == "" || (me.val() == ph && me.attr("readonly"))) {
                    me.val(ph).css('color', '#b4b4b4');
                }
                if (me.attr("type") == "text" && !me.attr("readonly")) {
                    if (me.val() == ph) {
                        me.css('color', '#b4b4b4');
                    }
                    me.focus(function () {
                        if (me.val() == ph) {
                            me.val("").css('color', '#3b3b3b');
                        }
                        else {
                            me.css('color', '#3b3b3b');
                        }
                    });
                    me.blur(function () {
                        if (me.val() == "") {
                            me.val(ph).css('color', '#b4b4b4')
                        }
                    });
                }
                else if (me.attr("type") == "text") {
                    if (typeof document.attachEvent != "undefined") {
                        me[0].attachEvent("onpropertychange", function () {
                            if (me.val() == ph) {
                                return;
                            }
                            if (me.val() == "") {
                                me.val(ph);
                                me.css('color', '#b4b4b4')
                            }
                            else {
                                me.css('color', '#3b3b3b')
                            }
                        });
                    }
                }
            }
        });
    }
    else {
        $('#div_searchlist input').each(function () {
            var me = $(this);
            var ph = me.attr('placeholder');
            if (ph && !me.attr("readonly")) {
                me.focus(function () {
                    me.attr('placeholder', "");
                });
                me.blur(function () {
                    me.attr("placeholder", ph);
                });
            }
            if (ph == me.val()) {
                me.css('color', '#b4b4b4');
            }
        });
    }
}
//初始文本框title属性 鼠标移进移出的边框样式 及过滤联动下拉框值
EHRCommonSearch.InitSelectData = function () {
    $("#div_searchlist .inptext_fl").each(function () {
        $(this).mouseleave(function () {
            if ($(this).children("input[type='text']").attr("readonly")) {
                $(this).children(".downList").hide();
                $(this).children("input[type='text']").css("border-color", "#c4c4c4");
            }
            else if ($(this).children(".downList").length == 2) {
                $(this).children(".downList:eq(0)").hide();
            }
            else {
                $(this).children(".downList").hide();
            }
        });
        if ($(this).attr("id") && $(this).children("input[type='text']").val() && $(this).children("input[type='text']").attr("readonly")) {
            if ($(this).attr("id") == "div_label") {
                $(this).children("input[type='text']").attr("title", $("#" + prefixControlID + "hid_titlelabel").val());
            }
            else {
                if ($('#needTitle').length<1&&$(this).children("input[type='hidden']").val()) {
                    var hidValue = $(this).children("input[type='hidden']").val().split('$');
                    var strValue = "";
                    for (var i = 0; i < hidValue.length; i++) {
                        if (hidValue[i] != "") {
                            strValue += hidValue[i].split('|')[0] + "+";
                        }
                    }
                    if (strValue != "") {
                        strValue = strValue.substring(0, strValue.length - 1);
                        $(this).children("input[type='text']").attr("title", strValue);
                    }
                }
            }
        }
    });
    var selectData = ["degreeto", "workyearto", "cursalaryto", "expectsalaryto"];
    for (var i = 0; i < selectData.length; i++) {
        var val = $("#" + prefixControlID + "hid_" + selectData[i].replace("to", "from")).val();
        if (val != "") {
            EHRCommonSearch.SetDownListData(val, prefixControlID + "txt_" + selectData[i], selectData[i], "1");
        }
    }
}
EHRCommonSearch.SetDownListData = function (val, showid, type, initflag) {
    var tmpTxt = (val == '0' || val == "01" || val == "") ? nolimited : (langen == '' ? "及以上" : "Or Above");
    var controlvalue;
    if (initflag == "1") {
        controlvalue = $("#" + showid).val();
    }
    switch (type) {
        case "degreeto":
            if (val == "10") {
                $("#divdrop_" + type + " a").hide();
                $("#" + showid).css('background', '#ebebe4');
                $("#" + showid).val(nolimited);
            }
            else {
                $("#" + showid).css('background', '');
                if (val != "1" && val != "") {
                    $("#" + showid).val(tmpTxt);
                }
                else {
                    $("#" + showid).val(nolimited);
                }
                $("#divdrop_" + type + " a").each(function () {
                    var curID = $(this).attr("id").split('_')[2];
                    if (curID == "99") {
                        if (val != "1" && val != "") {
                            $(this).html(tmpTxt);
                            $(this).attr('title', tmpTxt);
                        }
                        else {
                            $(this).html(nolimited);
                            $(this).attr('title', nolimited);
                        }
                        $(this).show();
                    }
                    else if (val > curID) {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                });
            }
            break;
        case "workyearto":
        case "cursalaryto":
        case "expectsalaryto":
            if (val == "") {
                $("#" + showid).val(nolimited);
            }
            else {
                $("#" + showid).val(tmpTxt);
            }
            if (type == "workyearto") {
                $("#divdrop_" + type + " a").each(function () {
                    var curID = $(this).attr("id").split('_')[2];
                    if (curID == "99") {
                        $(this).html(tmpTxt);
                        $(this).attr('title', tmpTxt);
                        $(this).show();
                    }
                    else if (val > curID) {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                });
            }
            else {
                var typefrom = type.replace("to", "from");
                var index = $("#divdrop_" + typefrom + " a").index($("#dic_" + typefrom + "_" + val));
                var curIndex = 0;
                $("#divdrop_" + type + " a").each(function () {
                    var curID = $(this).attr("id").split('_')[2];
                    if (curID == "99") {
                        $(this).html(tmpTxt);
                        $(this).attr('title', tmpTxt);
                        $(this).show();
                    }
                    else if (index >= curIndex) {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                    curIndex++;
                });
            }
            break;
    }
    if (initflag == "1") {
        $("#" + showid).val(controlvalue);
    }
    if ($("#" + showid).attr('placeholder') == $("#" + showid).val()) {
        $("#" + showid).css('color', '#b4b4b4');
    } else {
        $("#" + showid).css('color', '#3b3b3b');
    }
}
EHRCommonSearch.selectdata = function (showid, hidid) {
    var val = $("#" + hidid).val();
    var type = hidid.substring(hidid.lastIndexOf('_') + 1).replace("from", "to");
    showid = showid.replace("from", "to");
    hidid = hidid.replace("from", "to");
    $("#" + hidid).val("");
    EHRCommonSearch.SetDownListData(val, showid, type);
}
//标签搜索选择 begin
var EHRCommonSearchLabel = {};
EHRCommonSearchLabel.showLabelData = function (option) {
    window.config = {
        title: "",
        confirm: C_confirm_Title,
        cancel: C_Cancel_Title,
        maxSelectNum: 5,
        showid: "",
        hidid: "",
        hidtitleid: '',
        nomoreselecttmp: '',
        select_title: label_select_title
    }
    if (typeof (option) != "undefined") {
        $.extend(config, option);
    }
    config.title = layer_label_title.format(config.maxSelectNum);
    config.nomoreselecttmp = nomoreselect.format(config.maxSelectNum);
    EHRCommonSearchLabel.BuildLabelLayer();
};
EHRCommonSearchLabel.ConfirmLabel = function () {
    var labelname = "";
    var labelid = "";
    $('#div_selected_label').children("a").each(function () {
        labelname += html_decode($(this).children("b").html()) + "+";
        labelid += $(this).attr("tag") + ",";
    });
    if (labelid != "") {
        labelid = labelid.substring(0, labelid.length - 1);
        labelname = labelname.substring(0, labelname.length - 1);
    }
    $("#" + config.hidid).val(labelid);
    $("#" + config.showid).attr("title", labelname);
    $("#" + config.hidtitleid).val(labelname);
    labelname = getBytes(labelname, 18);
    $("#" + config.showid).val(labelname);
    EHRCommonSearchLabel.CloseLabelDiv('#popupLabel');
}
EHRCommonSearchLabel.CloseLabelDiv = function () {
    EHR.CloseDivMask();
    $("#popupLabel").hide();
    if (ie6) {
        $("select").show();
    }
}
EHRCommonSearchLabel.CancelSelected = function (labelid) {
    $("[tag='" + labelid + "']").remove();
    $("#popupLabel input[type='checkbox'][value='" + labelid + "']").attr("checked", false);
}
EHRCommonSearchLabel.BuildLabelLayer = function () {
    if ($("#popupLabel").length > 0) {
        $("#popupLabel").remove();
    }
    if (ie6) {
        $("select").hide();
    }
    var areadiv = $("<div id='popupLabel' style='display:none;width:800px;'></div>");
    areadiv.html(EHRCommonSearchLabel.GetCtmLabelHtml());
    $(document.body).append(areadiv);
    var postData = { "doType": "GetCtmLabelList" };
    EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalLabelRemarkAjaxNew.aspx", postData, EHRCommonSearchLabel.GetCtmLabelCompleteHandle);
};
EHRCommonSearchLabel.SelectLabel = function (labelid, labelname) {
    if ($('#div_selected_label').children("a").length >= config.maxSelectNum) {
        var top = $('#popupLabel').height() / 2;
        var left = $('#popupLabel').width() / 2 - 100;
        $('#subarea_more3').css({ 'top': top + 'px', 'left': left + 'px' }).fadeIn("slow").delay(1000).fadeOut(1000, "linear");
        $("#popupLabel input[type='checkbox'][value='" + labelid + "']").attr("checked", false);
        return;
    }
    var selectedHtml = "<a class=\"Common_region\" href=\"javascript:void(0);\" tag='" + labelid + "'><b style=\"color:#fff; font-weight:normal\">" + labelname + "</b><i onclick=\"EHRCommonSearchLabel.CancelSelected('" + labelid + "');\" class=\"Common_icon Common_icon_remove_white\"></i></a>";
    $('#div_selected_label').children(':last').after(selectedHtml);
}
EHRCommonSearchLabel.GetCtmLabelCompleteHandle = function (result) {
    var msgtype = $(result).find("msgtype").eq(0).text();
    var returninfo = $(result).find("returninfo").eq(0).text();
    if (msgtype == "0") {
        EHR.ShowBox(returninfo, 300);
        return;
    }
    $("#div_lblsellist").html(returninfo);
    $("#popupLabel input[type='checkbox']").bind("click", function () {
        var labelid = $(this).val();
        if ($(this).attr("checked")) {
            var labelname = $(this).next().html();
            $("[tag='" + labelid + "']").remove();
            EHRCommonSearchLabel.SelectLabel(labelid, labelname);
        }
        else {
            EHRCommonSearchLabel.CancelSelected(labelid);
        }
    });
    $('#div_selected_label').children("a").remove();
    if ($("#" + config.hidid).val() != "") {
        var labellist = $("#" + config.hidid).val().split(',');
        var selectedHtml = "";
        for (var i = 0; i < labellist.length; i++) {
            var labelid = labellist[i];
            var labelname = $("#popupLabel input[type='checkbox'][value='" + labelid + "']").next().html();
            $("#popupLabel input[type='checkbox'][value='" + labelid + "']").attr("checked", true);
            selectedHtml += "<a class=\"Common_region\" href=\"javascript:void(0);\" tag='" + labelid + "'><b style=\"color:#fff; font-weight:normal\">" + labelname + "</b><i onclick=\"EHRCommonSearchLabel.CancelSelected('" + labelid + "');\" class=\"Common_icon Common_icon_remove_white\"></i></a>";
        }
        $('#div_selected_label').children(':last').after(selectedHtml);
    }
    EHR.ShowDivBox("#popupLabel");
}
EHRCommonSearchLabel.GetCtmLabelHtml = function () {
    var strHtml = "";
    strHtml += "<div class=\"Common_panelBox Common_panel_select_location\">"
    strHtml += "<h2><p>" + config.title + "</p> <a class=\"Common_panel_closebtn\" href=\"javascript:void(0);\" onclick='EHRCommonSearchLabel.ConfirmLabel();'>" + config.confirm + "</a>"
    strHtml += " <a class=\"Common_panel_cancelbtn\" href=\"javascript:void(0)\" onclick='EHRCommonSearchLabel.CloseLabelDiv();'>" + config.cancel + "</a>"
    strHtml += "</h2>"
    strHtml += "<div class=\"Common_titleBottom\" id='div_selected_label'>"
    strHtml += "<label class=\"Common_titlebot_th\" style=\"top:1px;\">" + config.select_title + "</label>"
    strHtml += "</div><div class='inbox_div_pd' style='height:500px;overflow-y:auto;' id='div_lblsellist'>"
    strHtml += "</div>";
    strHtml += "<div id=\"subarea_more3\" style=\" text-align:center; z-index: 1199; display:none; position: absolute;color: #B47377; background-color: #f2dedf;width: 100px;height: 30px;font-size: 14px;\"><label style=\"font-size: 14px;line-height: 30px;\">" + config.nomoreselecttmp + "</label></div>";
    strHtml += "</div>";
    return strHtml;
}
//标签搜索选择 end
function html_decode(str) {
    var s = str;
    if (str.length == 0) return "";
    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&gt;/g, ">");
    s = s.replace(/&nbsp;/g, " ");
    s = s.replace(/&#39;/g, "\'");
    s = s.replace(/&quot;/g, "\"");
    s = s.replace(/<br>/g, "\n");
    return s;
}
